import httpInstance from "@/utils/http.js";
import {md5} from "js-md5";


/**
 * 用户登录
 * @param email
 * @param password
 * @param code
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export function loginApi({email, password}) {
    return httpInstance.post('/user/login', {
        email, password: md5(password)
    })
}

/**
 * 检查邮箱是否注册
 * @param email
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export function checkEmailApi(email) {
    return httpInstance.get('/user/checkEmail', {
        params: {
            email
        },

    })
}

/**
 * 邮箱验证码注册/登录
 * @param email
 * @param code
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export function registerApi({email, code}) {
    return httpInstance.post('/user/register', {
        email, code
    })
}

/**
 * 修改密码
 * @param email
 * @param password
 * @param code
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export function changePasswordApi({email,password,code}){
    return httpInstance('/user/changePassword',{
        method:"post",
        data:{
            email,password,code
        }
    })
}

/**
 * 退出登录
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export function logoutApi(){
    return httpInstance.get('/user/logout')
}

